package data;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class OrderResponse extends Response {
	private Order mOrder;
	
	public OrderResponse(int exitCode, Order order) {
		mExitCode = exitCode;
		mOrder = order;
	}
	
	public Order getOrder() {
		return mOrder;
	}
	
	public static final JsonDeserializer<OrderResponse> deserializer = new JsonDeserializer<OrderResponse>() {
		
		@Override
		public OrderResponse deserialize(JsonElement json, Type arg1, JsonDeserializationContext context) throws JsonParseException {
			int exitCode = json.getAsJsonObject().get("exitCode").getAsInt();
			Order order = context.deserialize(json.getAsJsonObject().get("result"), Order.class);
			return new OrderResponse(exitCode, order);
		}
	};
}
